/*
 * table_CcLinkageStack.c
 *
 *  Created on: 2012/03/29
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"


/*KIND_LINKAGE*/
typedef struct _LINKAGESTORAGE
{
	 UCHAR bExternal;
	 UCHAR bReferred;
	 UCHAR bFunction;
	 AST  astDel;  /* 2 */
	 AST  astTen;  /*3 */
	 AST  astAll; /*4 */
	 AST  astSym; /*4 */
} CCLINKAGESTORAGE, *PCCLINKAGESTORAGE;

static AST      gblCcLinkageStorage=0;

#define TableSize  (sizeof(CCLINKAGESTORAGE))
#define TableType  PCCLINKAGESTORAGE
#define stTable stCcLinkageStorageManager.memoryBlocks
#define maxTable stCcLinkageStorageManager.maxRecordNum
#define  maxNumPerBlk  (stCcLinkageStorageManager.astMaxNum_Block)

static TABLEMANAGER stCcLinkageStorageManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stCcLinkageStorageManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}

}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stCcLinkageStorageManager, resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}


static BOOL ClearTable( VOID )
{
	gblCcLinkageStorage = 0;
	return Clear_Com( &stCcLinkageStorageManager );
}
static BOOL ResetTable( VOID )
{
	gblCcLinkageStorage = 0;
	return Reset_Com( &stCcLinkageStorageManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stCcLinkageStorageManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
static BOOL  isExternal( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bExternal;
}
/* set method */
static BOOL  setExternal( AST index, BOOL value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->bExternal = value;
}
static BOOL  isFunction( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bFunction;
}
/* set method */
static BOOL  setFunction( AST index, BOOL value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->bFunction = value;
}
//	IDX_DECSYMCHAIN
/*  get method */
static AST  getDefinition( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDel;
}
/* set method */
static AST  setDefinition( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->astDel = idx;
}
//	IDX_TENSYMCHAIN
/*  get method */
static AST  getTenDecl( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTen;
}
/* set method */
static AST  setTenDecl( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->astTen = idx;
}
//	IDX_ALLSYMCHAIN
/*  get method */
static AST  getAll( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astAll;
}
/* set method */
static AST  setAll( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->astAll = idx;
}
//	IDX_REFERRED
/*  get method */
static BOOL  isReferInfo( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bReferred;
}
/* set method */
static BOOL  setReferInfo( AST index, BOOL v )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->bReferred = v;
}

const CCLINKAGESTACK_ACCESS stCCLinkageStackAccess = {
		ClearTable,
		ResetTable,
		AllocTable,
		getMaxLineNum,

//				ACCESS_IDX_FIELD definitionChain;
		{
				getDefinition,
				setDefinition
		},
//				ACCESS_IDX_FIELD tenDeclChain;
		{
				getTenDecl,
				setTenDecl
		},
//				ACCESS_IDX_FIELD allChain;
		{
				getAll,
				setAll
		},
//				ACCESS_BOOL_FIELD bExternal;
		{
				isExternal,
				setExternal
		},
		{
				isReferInfo,
				setReferInfo
		},
		{
				isFunction,
				setFunction
		}
};
/* end of file */

